package cn.admin.service.impl;

import cn.admin.dao.QuotaMapper;
import cn.admin.service.QuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 20:32 2019/3/23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class QuotaServiceImpl implements QuotaService {

    @Autowired private QuotaMapper quotaMapper;

    @Override
    public String getAllQuota() {
        double loanAmount = quotaMapper.findLoanAmount();
        String money="0";
        if (loanAmount!=0){
            money = new DecimalFormat("###,###.00").format(loanAmount);
        }
        return money;
    }

    @Override
    public String getTotalLoanAmount() {
        double totalLoanAmount = quotaMapper.findTotalLoanAmount();
        String money="0";
        if (totalLoanAmount!=0){
            money = new DecimalFormat("###,###.00").format(totalLoanAmount);
        }
        return money;
    }

    @Override
    public boolean updateQuotaMoney(double loan, int userId) {
        return quotaMapper.updateQuotaMoney(loan,userId)==1?true:false;
    }

}
